package imli.me.lquan.base.app;

import android.app.Application;
import android.content.Context;
import android.os.Build;
import android.util.DisplayMetrics;
import android.view.WindowManager;

import java.util.Locale;

import imli.me.lquan.BuildConfig;

/**
 * Created by Em on 2017/12/19.
 */

public class BaseApplication extends Application {

    /**
     * TAG
     */
    private static final String TAG = "Application";

    /**
     * Application Context
     */
    private static Context mContext;

    @Override
    public void onCreate() {
        super.onCreate();
        this.initialization();
    }

    /**
     * initialization
     */
    protected void initialization() {
        this.initContext();
    }

    /**
     * init content
     */
    private void initContext() {
        mContext = this;
    }

    /**
     * build accept language
     * @return
     */
    protected String buildAcceptLanguage() {
        Locale locale = Locale.getDefault();
        return String.format("%s-%s,%s;q=0.8,en-US;q=0.6,en;q=0.4",
                locale.getLanguage(), locale.getCountry(), locale.getLanguage());
    }

    /**
     * build user agent
     * @return
     */
    protected String buildUserAgent() {
        String userAgent = String.format("Retrofit %s Android (%d/%s)", BuildConfig.VERSION_NAME, Build.VERSION.SDK_INT, Build.VERSION.RELEASE);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            DisplayMetrics metrics = new DisplayMetrics();
            WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
            wm.getDefaultDisplay().getRealMetrics(metrics);
            userAgent += String.format(" (%d; %dx%d)", metrics.densityDpi, metrics.widthPixels, metrics.heightPixels);
        }
        return userAgent;
    }

    /**
     * get tag
     * @return
     */
    public static String getTag() {
        return TAG;
    }

    /**
     * get application context
     * @return
     */
    public static Context getContext() {
        return mContext;
    }
}
